<?php


namespace app\voip\func;


use app\voip\model\ECallGroup;
use app\voip\model\ECallTask;
use app\voip\model\ECallTaskUser;

class CallTaskFunc
{
    /**
     * @param $where
     * @param $rows
     * @param $param
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    static function getList($where, $rows, $param)
    {
        $obj = new ECallTask();
        return $obj->where($where)->order('id desc')->paginate($rows,false,['query'=>$param]);
    }
    /**
     * @param $where
     * @param $rows
     * @param $param
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    static function getListAndUser($where, $rows, $param)
    {
        $obj = new ECallTask();
        return $obj->alias('c1')->where($where)->join('e_call_task_user c2','c1.id=c2.tid')->order('c1.id desc')->field('c1.*')->paginate($rows,false,['query'=>$param]);
    }
    static function add($data)
    {
        $obj = new ECallTask($data);
        $obj->allowField(true)->save();
        return $obj->id;
    }
    static function taskAddUserAll($data)
    {
        $obj= new ECallTaskUser();
        return $obj->saveAll($data);
    }

    /**
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function findUserTaskInfo($where)
    {
        $obj = new ECallTaskUser();
        return $obj->alias('c1')->join('e_call_task c2','c1.tid=c2.id')->where($where)->field('c2.*')->find();
    }

    /**
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function getOptionList($where)
    {
        $obj = new ECallTask();
        return $obj->alias('c1')->where($where)->join('e_call_task_user c2','c1.id=c2.tid')->order('c1.id desc')->field('c1.*')->select();
    }

    /**
     * @param $ids
     * @return int
     */
    static public function taskDel($ids)
    {
        return ECallTask::destroy($ids);
    }

    /**
     * @param $where
     * @return int
     */
    static public function taskUserDel($where)
    {

        return ECallTaskUser::destroy($where);
    }

    /**
     * @param $where
     * @return ECallTask
     */
    static public function updateTask($where)
    {
        return ECallTask::update($where);
    }
}